<template>
	<view class="content">
		
		
	
		
		

		<image class="imagebg" src="/static/image/erweicode/myinveterBg.png" mode=""></image>
		
		

		
		<view class="invite-c">
			
			<view class="topView">
				
				<text class='invite-w-num'>{{code}}</text>
				<view class='invite-w-t'>专属邀请码</view>
				
			</view>
			
			
			<view class='hint1'>邀请的好友也可在注册时直接填写邀请码</view>
			
			<view class="imageBox">
				<image class="share-img" :src="poster" mode="aspectFill"></image>
				
			</view >
			
			
			<view class='hint2'>长按图片即可保存</view>
			
			

		
			</view>
		
	
		</view>

	</view>
</template>

<script>
	import { h5Url } from '@/config/config.js'
	// #ifdef MP-TOUTIAO
	import {ttPlatform} from '@/config/config.js'
	// #endif
	export default {
		data() {
			return {
				code: '',
				money: 0,
				number: 0,
				is_superior: false,
				inviteKey: '',
				imageUrl: '/static/image/share_image.png',
                shareUrl: '/pages/share/jump',
				poster: ''
			}
		},
		computed: {
			appTitle() {
				return this.$store.state.config.shop_name;
			}
		},
		onShow() {
			this.getInviteData();
			this.ifwxl();
			this.createPoster();
		},
		methods: {
			// 判断是不是微信浏览器
			ifwxl(){
				this.ifwx = this.$common.isWeiXinBrowser()
			},
			//获取数据
			getInviteData() {
				this.$api.myInvite(res => {
					
			
					
					this.code = res.data.code;
					this.money = res.data.money;
					this.number = res.data.number;
					this.is_superior = res.data.is_superior;
				});
			},
			//去佣金明细
			toMoney() {
				this.$common.navigateTo('../balance/details?status=5');
			},
			//去邀请列表
			toList() {
				this.$common.navigateTo('./list');
			},
			//填写设置要求
			setMyInvite() {
				let data = {
					code: this.inviteKey
				}
				this.$api.setMyInvite(data, res => {
					if (res.status) {
						this.$common.successToShow('邀请码填写成功');
						this.is_superior = true;
					} else {
						this.$common.errorToShow(res.msg);
					}
				});
			},
			// 生成邀请海报
			createPoster() {                
				let data = {
				    page: 1,//首页
				    type: 2,//海报
				}
				let userToken = this.$db.get('userToken')
				if (userToken) {
				    data.token = userToken
				}
				
				// #ifdef H5 || APP-PLUS || APP-PLUS-NVUE
				data.client = 1;
				data.url = h5Url + 'pages/share/jump'
				// #endif
				
				// #ifdef MP-WEIXIN
				data.client = 2;
				data.url = 'pages/share/jump'
				// #endif
				
				// #ifdef MP-TOUTIAO
				data.client = 4;
				data.url = '/pages/share/jump'
				// #endif
				
				// #ifdef MP-ALIPAY
				data.client = 6;
				data.url = '/pages/share/jump'
				// #endif
				
				this.$api.share(data, res => {
					
					this.poster = res.data;
					
					// if (res.status) {
					// 	this.$common.navigateTo('/pages/share?poster=' + encodeURIComponent(res.data))
					// } else {
					// 	this.$common.errorToShow(res.msg)
					// }
				});
			},
			//复制URL链接
			copyUrl() {
				let data = {
				    page: 1,//首页
				    type: 1,//海报
				}
				let userToken = this.$db.get('userToken')
				if (userToken) {
				    data.token = userToken
				}
				
				// #ifdef H5 || APP-PLUS || APP-PLUS-NVUE
				data.client = 1;
				data.url = h5Url + 'pages/share/jump'
				// #endif
				
				// #ifdef MP-WEIXIN
				data.client = 2;
				data.url = 'pages/share/jump'
				// #endif
				
				// #ifdef MP-TOUTIAO
				data.client = 4;
				data.url = '/pages/share/jump'
				// #endif
				
				// #ifdef MP-ALIPAY
				data.client = 6;
				data.url = '/pages/share/jump'
				// #endif

                let _this = this;
				this.$api.share(data, res => {
					if(res.status) {
						uni.setClipboardData({
							data: res.data,
							success:function(data){
								_this.$common.successToShow('复制成功');
							}, 
							fail:function(err){
								_this.$common.errorToShow('复制分享URL失败');
							}
						})
					} else {
						_this.$common.errorToShow('复制分享URL失败');
					}
				});
			},
            //获取分享URL
            getShareUrl() {
                let data = {
                    client: 2,
                    url: "/pages/share/jump",
                    type: 1,
                    page: 1,
                };
                let userToken = this.$db.get('userToken');
                if (userToken && userToken != '') {
                	data['token'] = userToken;
                }
                this.$api.share(data, res => {
					
	
					
                    this.shareUrl = res.data
                });
            }
		},
		//分享
		onShareAppMessage() {
			return {
				title: this.$store.state.config.share_title,
				// #ifdef MP-ALIPAY
				desc: this.$store.state.config.share_desc,
				// #endif
				imageUrl: this.$store.state.config.share_image,
				path: this.shareUrl
			}
		}
	}
</script>

<style>
	
.content{
	
	/* background-color: #007AFF; */
	
}
	
.imagebg{
	
	position: absolute;
	
	left: 0upx;
	
	top: 0upx;
	
	width: 750upx;
	
	height: 1159upx;
	
	z-index: -99;
	
	
}


	.invite-c {
		position: absolute;
		z-index: 67;
		width: 678upx;
		height: 613upx;
		
		margin-top: 471upx;
		
		margin-left: 36upx;
		
		border-radius: 22upx;
		
		background-color: #FFFFFF;
		
		display: flex;
		
		flex-direction: column;
		
		align-items: center;
		
		/* padding: 0 30upx; */
		/* top: 488upx; */
		/* background: linear-gradient(to right, #4c21d2, #4864f8); */
	}
	
	
.topView{
	
	margin-top: -25upx;
	
	/* margin-left: 60upx; */
	
	background-color: rgb(76, 118, 247);
		
	width: 558upx;
	
	border-radius: 11upx;
	
	height: 98upx;
	
	display: flex;
	
	flex-direction: row;
	
	justify-content: flex-end;
	
}





	.invite-w-num {
		
		width: 327upx;
		
		height: 98upx;
		
		line-height: 98upx;
		
		text-align: center;
		
		color: #FFFFFF;
		font-weight: bold;
		/* display: block; */
		font-size: 48upx;
		/* margin-top: 20upx; */
	}
	
	
	.invite-w-t {
		width: 231upx;
		height: 98upx;
		color: #fff;
		border-radius: 11upx;
		font-size: 32upx;
		
		line-height: 98upx;
		
		text-align: center;
		
		
	
	
		background-color: rgb(141, 163, 183);
	}
	
	
.hint1{
	
	font-size: 28upx;
	
	color: #000000;
	
	margin-top: 25upx;
	
	
}

.hint2{
	
	font-size: 32upx;
	
	color: #000000;
	
	margin-top: 25upx;
	
	
	
	
}

.imageBox{
	
	width: 350upx;
	
	height: 350upx;
	
	margin-top: 17upx;
	
	
	overflow: hidden;
	
	background-color: rgb(246, 246, 246);
	
	border-radius: 22upx;
	
	border-width: 2upx;

	
	border-color: #007AFF;
	
	border-style: solid;
	

	
}
	
.share-img{
	
/* 	margin-left: -60upx;
	
	margin-top: 30upx; */
	
	width: 100%;
	
	height: 100%;

	

	
	z-index: 9999;
	
	
}
	
</style>
